package com.xctech.yace.util;


public class StringUtil {
    /**
     * 192.168.0.171:26379 拆分字符串
     * @param from
     * @return
     */
    public static String[] extractParts(String from){
        int idx     = from.lastIndexOf(":");
        String host = idx != -1 ? from.substring(0, idx)  : from;
        String port = idx != -1 ? from.substring(idx + 1) : "";
        return new String[] { host, port };
    }

    /**
     * 序号格式转换40.35756
     */
    public static Long convertActseq(String actSeq){
        String replace = actSeq.replace(".", "");
        return Long.parseLong(replace);
    }

    /**
     * 左补零
     * @param str
     * @param digit
     * @return
     */
    public static String lpad(String str,Integer digit){
        Integer len = str.length();
        StringBuilder sb = new StringBuilder(str);
        while (len < digit){
            sb.insert(0,"0");
            len = sb.length();
        }
        return sb.toString();
    }

    /**
     * 右补零
     * @param str
     * @param digit
     * @return
     */
    public static String rpad(String str,Integer digit){
        Integer len = str.length();
        StringBuilder sb = new StringBuilder(str);
        while (len < digit){
            sb.append("0");
            len = sb.length();
        }
        return sb.toString();
    }

    /**
     * 右补空格
     * @param str
     * @param digit
     * @return
     */
    public static String rpadSpace(String str,Integer digit){
        Integer len = str.length();
        StringBuilder sb = new StringBuilder(str);
        while (len < digit){
            sb.append(" ");
            len = sb.length();
        }
        return sb.toString();
    }


}
